package me.yobol.greentable.service;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

import me.yobol.greentable.bean.DishesCommentBean;
import me.yobol.greentable.dao.IDishesCommentDAO;
import me.yobol.greentable.dao.impl.DishesCommentDAOImpl;
import me.yobol.greentable.util.sql.ConnectionFactory;

/**
 * @author Yobol
 *
 */
public class DishesCommentService {
	
	private static Connection ctn = ConnectionFactory.getInstance().getConnection();
	private static IDishesCommentDAO dcdi = new DishesCommentDAOImpl();
	
	public static int createDishesComment(DishesCommentBean comment){
		int result = -1;
		
		try {
			result = dcdi.save(ctn, comment);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		return result;
	}
	
	public static boolean deleteDishesComment(int commentId,int customerId){
		
		DishesCommentBean comment = null;
		try {
			comment = dcdi.get(ctn, commentId);
			if(comment.getUserId() != customerId){
				return false;
			}
			dcdi.delete(ctn, commentId);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return true;
	}
	
	public static List<DishesCommentBean> getDishesCommentByDishesId(int dishesId){
		List<DishesCommentBean> comments = null;
		try {
			comments = dcdi.getByDishesId(ctn, dishesId);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return comments;
	}

}
